#!/bin/bash

awk 'BEGIN{
	FS =",";
	OFS=",";
	start=1297980408;
	i=1;
	count[""]=0;
	
}{
	time=$1-start;
	if(time<=180*i && time>=180*(i-1))
	{
		if($2!=0)
		{
		  pow8[i]++;
		  power8[i]+=$2;
	    }
		if($3!=0)
		{
		  pow6[i]++;
		  power6[i]+=$3;
	    }
		if($5!=0)
		{
		   cur8[i]++;
		   current8[i]+=$5;
		}		  
		if($6!=0)
		{
			cur6[i]++;
			current6[i]+=$6;
		}
	}
	else{
		i++;
		if($2!=0)
		{
		  pow8[i]++;
		  power8[i]+=$2;
	    }
		if($3!=0)
		{
		  pow6[i]++;
		  power6[i]+=$3;
	    }
		if($5!=0)
		{
		   cur8[i]++;
		   current8[i]+=$5;
		}		  
		if($6!=0)
		{
			cur6[i]++;
			current6[i]+=$6;
		}
	}
	
}END{
		for(k in pow8)
		{
			if(pow8[k]!=0 && pow6[k]!=0)
			{
				print (k-1)*3,power8[k]/pow8[k],power6[k]/pow6[k],power8[k]/pow8[k]+power6[k]/pow6[k];
			}
		}	
}' $1 |sort -t "," -n -k1,1n >>3power
	
